<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once "class/Load.class.php";
require_once "class/Config.class.php";
require_once "class/Inputs.class.php";
require_once "class/StatusRoster.class.php";
require_once "class/Localization.class.php";
require_once "class/SessionRoster.class.php";
require_once "class/SubscriptionManager.class.php";

$load = Load::GetInstance();
$config = Config::GetInstance();
$inputs = Inputs::GetInstance();
$localization = Localization::GetInstance();
$status_roster = StatusRoster::GetInstance();
$session_roster = SessionRoster::GetInstance();

if ( $session_roster->IsAdminConnected() )
{
	$session_roster->Redirect("admin.php");
}

if ($session_roster->IsConnected() == false)
{
	$session_roster->Redirect("connection.php");
}

if ( $inputs->HasPostData('connect') )
{
	if ( $inputs->Post('password') == $config->GetAdminPassword() )
	{
		$session_roster->ConnectAdmin();
		$session_roster->Redirect('admin.php');
	}
	else
	{
		$status_roster->AddError( $localization->Get('incorrect password') );
		
		$session_roster->SaveStatus($status_roster);
		$session_roster->Redirect('admin_connection.php');
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
	<head>
		<title>LZRoster<?php echo $config->HasRosterTitle() ?  " - ".$config->GetRosterTitle() : null; ?></title>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/_.css" />
		<link rel="stylesheet" media="screen" type="text/css" href="styles/admin_connection.css" />
	</head>
	<body>
		
		<?php require_once "inc/head.php"; ?>
		<?php require_once "inc/hmenu.php"; ?>
		
		<h2><?php echo $localization->Get('admin login'); ?></h2>
		
		<?php
		if ($status_roster->HasMessage() or $session_roster->HasStatus())
		{
		?>
			
			<p>
				<?php echo $localization->Get('this page produced some messages. please refer to the following lines'); ?>
			</p>
			
			<?php echo $session_roster->HasStatus() ? $session_roster->GetStatus()->GetStack_InList() : $status_roster->GetStack_InList(); ?>
			
			<p>
				<?php echo $localization->Get('you can refresh the page %s and try again', "admin_connection.php"); ?>
			</p>
			
		<?php
		}
		else
		{
		?>
		
		<form action="admin_connection.php" method="post" id="formconnect" class="send">
		<p id="introduction">
			<em><?php echo $localization->Get('please enter the admin password'); ?></em>
		</p>
		
		<p id="loginpassword">
			<label for="password">
				<?php echo $localization->Get('password'); ?>:
			</label>
			<input
				type="password"
				name="password"
				id="password"
			/><br />
		</p>
		
		<p id="submit">
			<a href="javascript:;"><img src="img/login.png" alt="" onclick="document.getElementById('formconnect').submit();" /></a><br />
			<input type="hidden" name="connect" />
		</p>
		</form>
		
		<?php
		}
		?>
		
		<?php require_once "inc/foot.php"; ?>
		
	</body>
</html>